<template>
	<view class="box page-box">
		<view class="top-nav">
			<view class="top-left" @click="toTabBar">
				<uni-icons type="back" size="30"></uni-icons>
			</view>
		</view>
		<view class="pagetitle">
			{{topicTitle ||'答案解析'}}
		</view>
		<view class="topic" v-for="(item,index) in analysis" :key="item.id">
			<AnswerKeys :item="item" :index="index"></AnswerKeys>
			<view class="answer userAnswer">
				<view>您的答案是: <text>{{item.userAnswer}}</text> </view>
				<view class="userResult">
					<text v-if="testQuestionsresult(item)" style="color:#5aef7d;">√</text>
					<text v-else class="trueResult" style="color:red">X</text>
				</view>
			</view>
			<view class="answer">正确答案是: <text>{{item.answers + ''}}</text></view>
		</view>
	</view>
</template>

<script>
	import AnswerKeys from '../../components/AnswerKeys.vue'
	export default {
		components: {
			AnswerKeys
		},
		data() {
			return {
				analysis: [],
				topicTitle: '',
				delta: 1
			};
		},
		computed: {

		},
		methods: {
			toTabBar() {
				// uni.switchTab({
				// 	url: '/pages/lecture/lecture'
				// })
				uni.navigateBack({
					delta: +this.delta
				})
			},
			testQuestionsresult(item) {
				if (!(item.userAnswer.split(',').length === item.answers.length)) return false
				//长度相等
				if (item.userAnswer.length === 1) {
					//单选
					return item.userAnswer === item.answers + '' ? true : false
				} else {
					//多选
					return item.userAnswer.split(',').every(item2 => {
						return item.answers.some(item3 => item3 === item2)
					})
				}
			}
		},
		async onLoad(option) {
			if (option.delta) {
				this.delta = option.delta
			}
			this.topicTitle = option.topicTitle
			const r = await uni.$http.get(`/api/question/queryBySubjectCode/${option.subjectCode}`)
			this.analysis = r.data.data
		}
	}
</script>

<style lang="scss">
	.top-nav {
		height: 160rpx;
		display: flex;
		align-items: center;

		.top-left {
			background-color: rgba(0, 0, 0, 0.1);
			display: flex;
			justify-content: center;
			align-items: center;
			border-radius: 40rpx;
			width: 80rpx;
			height: 80rpx;
		}

	}

	.pagetitle {
		font-weight: 700;
		font-size: 40rpx;
		text-align: center;
	}

	.answer {
		margin: 20rpx;
	}

	.userAnswer {
		display: flex;
		justify-content: space-between;

		.userResult {
			font-size: 40rpx;
			font-weight: 700;
		}
	}
</style>
